package cn.iocoder.yudao.module.product.util;

import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.yudao.module.product.enums.ErrorCodeConstants;
import lombok.extern.slf4j.Slf4j;

/**
 * Description:
 * Author: li
 * Date: 2024/3/28
 */
@Slf4j
public class ProductUtil {

    public static void checkFieldNullable(Long id, Object object, String fieldName) {
        final Object fieldValue = ReflectUtil.getFieldValue(object, fieldName);
        if (fieldValue == null || (fieldValue instanceof String && StrUtil.isEmpty((String) fieldValue))) {
            log.warn("字段为空, id = {}, fieldName = {}, fieldValue = {}", id, fieldName, fieldValue);
            throw ServiceExceptionUtil.exception(ErrorCodeConstants.SPU_FIELD_NULL_ERROR, fieldName);
        }
    }

}
